package com.lelv.framework.bo;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.lelv.framework.dao.IFunctionDao;
import com.lelv.framework.model.Function;
import com.lelv.framework.plugin.TreeNode;

public class FunctionBoImpl implements IFunctionBo{
	private IFunctionDao functionDao;

	public IFunctionDao getFunctionDao() {
		return functionDao;
	}

	public void setFunctionDao(IFunctionDao functionDao) {
		this.functionDao = functionDao;
	}

	@Override
	public List getTreeNodes(Long id,Integer adminLevel) {
		// TODO Auto-generated method stub

		List<Function> temp = this.functionDao.getTreeNodes(id,adminLevel);
		List<TreeNode> treeNodeList = new ArrayList<TreeNode>();

		for(Function fun : temp){
			TreeNode tempNode = new TreeNode();
			tempNode.setId(fun.getId());
			tempNode.setName(fun.getFunctionName());
			if(fun.getParent() != null){
				tempNode.setPid(fun.getParent().getId());
			}else{
				tempNode.setPid(null);
			}
			Set childs = fun.getChilds();
			if(childs.size() > 0){
				tempNode.setIsParent(true);
				tempNode.setIsLeaf(false);
			}else{
				tempNode.setIsParent(false);
				tempNode.setIsLeaf(true);
				tempNode.setUrl(fun.getFunctionUrl());
				tempNode.setTarget("main");
			}
			treeNodeList.add(tempNode);
		}

		return treeNodeList;
	}
}
